/**
 * author wen
 * &copy; CUNYU GROUP
 * email wjd_13@hotmail.com
 */
package com.cunyu.util;

import com.cunyu.service.PushService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

/**
 * 自动推单逻辑
 * @author win
 * 2019/05/21-10:34
 */
public class PushCheckUtil {

    private static Logger logger = LoggerFactory.getLogger(PushCheckUtil.class) ;

    private static String[] columns = {
            "hashouse","hascar","haswld","creditcard","social_security","haslife",
            "loan_amount","job","income","citycode","provident_fund","incometype"
    } ;

    public static void check(List<Map<String, Object>> users,
                             List<Map<String, Object>> orders,
                             PushService pushService){
        for (Map<String,Object> user : users){
            int uid = (int) user.get("uid") ;
            boolean like = false ;
            for (Map<String,Object> order :orders ){
                boolean match = true ;
                for (String col:columns){
                    if(!comp(user,order,col)){
                        // 有不符合条件，退出此客户比较
                        match = false ;
                        break;
                    }
                }
                // 判断是否所有条件都符合，具有符合条件的客户
                if(match){
                    like = true ;
                    break ;
                }
            }
            // 有需求的客户，则退出比较。
            if(like){
                pushService.push("订单推送","当前有符合您订阅条件的订单，请尽快登录抢单吧！",uid);
            }
        }
    }

    private static boolean comp(Map<String, Object> user, Map<String, Object> order, String col) {
        int v = (int)user.get(col);
        if(v == -1)
            return true;
        if(col.equals("citycode") && v == 0){
            return true ;
        }
        int t = (int)order.get(col) ;
        return t == v ;
    }

}
